<template>
  <a-drawer
    :title="title"
    :width="width"
    placement="right"
    :closable="false"
    @close="close"
    :visible="visible">
  
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="全库唯一码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'puid', validatorRules.puid]" placeholder="请输入全库唯一码"></a-input>
        </a-form-item>
        <a-form-item label="采购方总部编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'purchaserHqCode', validatorRules.purchaserHqCode]" placeholder="请输入采购方总部编码"></a-input>
        </a-form-item>
        <a-form-item label="销售订单号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'soNo', validatorRules.soNo]" placeholder="请输入销售订单号"></a-input>
        </a-form-item>
        <a-form-item label="供应商编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'supplierCode', validatorRules.supplierCode]" placeholder="请输入供应商编码"></a-input>
        </a-form-item>
        <a-form-item label="供应商名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'supplierName', validatorRules.supplierName]" placeholder="请输入供应商名称"></a-input>
        </a-form-item>
        <a-form-item label="采购方公司编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'buyerCode', validatorRules.buyerCode]" placeholder="请输入采购方公司编码"></a-input>
        </a-form-item>
        <a-form-item label="采购方公司名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'buyerName', validatorRules.buyerName]" placeholder="请输入采购方公司名称"></a-input>
        </a-form-item>
        <a-form-item label="采购方区域" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'buyerArea', validatorRules.buyerArea]" placeholder="请输入采购方区域"></a-input>
        </a-form-item>
        <a-form-item label="采购方公司省份" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'buyerProvince', validatorRules.buyerProvince]" placeholder="请输入采购方公司省份"></a-input>
        </a-form-item>
        <a-form-item label="品类编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'categoryCode', validatorRules.categoryCode]" placeholder="请输入品类编码"></a-input>
        </a-form-item>
        <a-form-item label="种类编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'subclassCode', validatorRules.subclassCode]" placeholder="请输入种类编码"></a-input>
        </a-form-item>
        <a-form-item label="销售订单状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'soStatus', validatorRules.soStatus]" placeholder="请输入销售订单状态"></a-input>
        </a-form-item>
        <a-form-item label="来源数据" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'dataSource', validatorRules.dataSource]" placeholder="请输入来源数据"></a-input>
        </a-form-item>
        <a-form-item label="来源数据创建时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择来源数据创建时间" v-decorator="[ 'datasourcecreatetime', validatorRules.datasourcecreatetime]" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="合同编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'concode', validatorRules.concode]" placeholder="请输入合同编号"></a-input>
        </a-form-item>
        <a-form-item label="逻辑删除" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'isdeleted', validatorRules.isdeleted]" placeholder="请输入逻辑删除"></a-input>
        </a-form-item>
        <a-form-item label="更新时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'modifytime', validatorRules.modifytime]" placeholder="请输入更新时间"></a-input>
        </a-form-item>
        <a-form-item label="状态表示" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'ioflag', validatorRules.ioflag]" placeholder="请输入状态表示"></a-input>
        </a-form-item>
        <a-form-item label="错误信息" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'message', validatorRules.message]" placeholder="请输入错误信息"></a-input>
        </a-form-item>
        <a-form-item label="本条数据是新增/更新" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'status', validatorRules.status]" placeholder="请输入本条数据是新增/更新"></a-input>
        </a-form-item>
        <a-form-item label="全局流水号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'transno', validatorRules.transno]" placeholder="请输入全局流水号"></a-input>
        </a-form-item>
        <a-form-item label="预留字段1" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'remark1', validatorRules.remark1]" placeholder="请输入预留字段1"></a-input>
        </a-form-item>
        <a-form-item label="预留字段2" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'remark2', validatorRules.remark2]" placeholder="请输入预留字段2"></a-input>
        </a-form-item>
        <a-form-item label="预留字段3" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'remark3', validatorRules.remark3]" placeholder="请输入预留字段3"></a-input>
        </a-form-item>
        <a-form-item label="预留字段4" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'remark4', validatorRules.remark4]" placeholder="请输入预留字段4"></a-input>
        </a-form-item>
        <a-form-item label="预留字段5" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'remark5', validatorRules.remark5]" placeholder="请输入预留字段5"></a-input>
        </a-form-item>
        
      </a-form>
    </a-spin>
    <a-button type="primary" @click="handleOk">确定</a-button>
    <a-button type="primary" @click="handleCancel">取消</a-button>
  </a-drawer>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import JDate from '@/components/jeecg/JDate'  
  
  export default {
    name: "EipSalesOrderModal",
    components: { 
      JDate,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules:{
        puid:{rules: [{ required: true, message: '请输入全库唯一码!' }]},
          purchaserHqCode: { rules: [{ required: true, message: '请输入采购方总部编码!' }] },
          supplierCode: { rules: [{ required: true, message: '请输入供应商编码!' }] },
          supplierName: { rules: [{ required: true, message: '请输入供应商名称!' }] },
          soNo: { rules: [{ required: true, message: '请输入销售订单号!' }] },
          buyerCode: { rules: [{ required: true, message: '请输入采购方公司编码!' }] },
          buyerName: { rules: [{ required: true, message: '请输入采购方公司名称!' }] },
          buyerArea: {},
          buyerProvince: { rules: [{ required: true, message: '请输入采购方公司省份!' }] },
          categoryCode: { rules: [{ required: true, message: '请输入品类编码!' }] },
          subclassCode: { rules: [{ required: true, message: '请输入种类编码!' }] },
          soStatus: {},
          dataSource: { rules: [{ required: true, message: '请输入数据来源!' }] },
          dataSourceCreateTime: { rules: [{ required: true, message: '请输入来源数据创建时间!' }] },
          conCode: { rules: [{ required: true, message: '请输入合同编号!' }] },
          isDeleted: { rules: [{ required: true, message: '请输入删除标志!' }] },
          modifyTime: {},
          soItemNo: { rules: [{ required: true, message: '请输入销售订单行项目号!' }] },
          supplierSoRelType: {},
          eipPoNo: {},
          poItemId: { rules: [{ required: true, message: '请输入采购订单行项目ID!' }] },
          productCode: { rules: [{ required: true, message: '请输入物资编码!' }] },
          productName: { rules: [{ required: true, message: '请输入物资名称!' }] },
          productUnit: { rules: [{ required: true, message: '请输入物资单位!' }] },
          planDeliveryDate: { rules: [{ required: true, message: '请输入采购订单厂家计划交货日期!' }] },
          planDeliveryPlace: {},
          planDeliveryPlaceDesc: {},
          productAmount: { rules: [{ required: true, message: '请输入物资数量!' }] },
          productIdGrpNo: {},
          ownerId: {},
          openId: {},
          ioflag: {},
          message: {},
          status: {},
          transno: {},
          remark1: {},
          remark2: {},
          remark3: {},
          remark4: {},
          remark5: {}
        },
        url: {
          add: "/eipSalesOrder/add",
          edit: "/eipSalesOrder/edit",
        }
     
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'puid', 'purchaserHqCode', 'soNo', 'supplierCode', 'supplierName', 'buyerCode', 'buyerName', 'buyerArea', 'buyerProvince', 'categoryCode', 'subclassCode', 'soStatus', 'dataSource', 'dataSourceCreateTime', 'conCode', 'isDeleted', 'modifyTime', 'soItemNo', 'supplierSoRelType', 'eipPoNo', 'poItemId', 'productCode', 'productName', 'productUnit', 'planDeliveryDate', 'planDeliveryPlace', 'planDeliveryPlaceDesc', 'productAmount', 'productIdGrpNo', 'ownerId', 'openId', 'ioflag', 'message', 'status', 'transno', 'remark1', 'remark2', 'remark3', 'remark4', 'remark5'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.puid){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'puid', 'purchaserHqCode', 'soNo', 'supplierCode', 'supplierName', 'buyerCode', 'buyerName', 'buyerArea', 'buyerProvince', 'categoryCode', 'subclassCode', 'soStatus', 'dataSource', 'dataSourceCreateTime', 'conCode', 'isDeleted', 'modifyTime', 'soItemNo', 'supplierSoRelType', 'eipPoNo', 'poItemId', 'productCode', 'productName', 'productUnit', 'planDeliveryDate', 'planDeliveryPlace', 'planDeliveryPlaceDesc', 'productAmount', 'productIdGrpNo', 'ownerId', 'openId', 'ioflag', 'message', 'status', 'transno', 'remark1', 'remark2', 'remark3', 'remark4', 'remark5'))
      }
      
    }
  }
</script>

<style lang="less" scoped>
/** Button按钮间距 */
  .ant-btn {
    margin-left: 30px;
    margin-bottom: 30px;
    float: right;
  }
</style>